# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=poppler

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.26.2
pkgrel=1
pkgdesc="PDF rendering library based on xpdf 3.0 (mingw-w64)"
arch=('any')
url="http://poppler.freedesktop.org"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config" "${MINGW_PACKAGE_PREFIX}-glib2" "${MINGW_PACKAGE_PREFIX}-qt5")
depends=("${MINGW_PACKAGE_PREFIX}-icu"
        "${MINGW_PACKAGE_PREFIX}-libtiff"
        "${MINGW_PACKAGE_PREFIX}-curl"
        "${MINGW_PACKAGE_PREFIX}-openjpeg"
        "${MINGW_PACKAGE_PREFIX}-libpng"
        "${MINGW_PACKAGE_PREFIX}-freetype"
        "${MINGW_PACKAGE_PREFIX}-libjpeg"
        "${MINGW_PACKAGE_PREFIX}-cairo"
        "${MINGW_PACKAGE_PREFIX}-zlib"
        "${MINGW_PACKAGE_PREFIX}-poppler-data")
optdepends=("${MINGW_PACKAGE_PREFIX}-glib2: libpoppler-glib"
            "${MINGW_PACKAGE_PREFIX}-qt5: libpoppler-qt5")
options=('strip' 'staticlibs')
source=("http://poppler.freedesktop.org/poppler-${pkgver}.tar.xz"
        "poppler-0.26-mingw-wstring.patch"
        "give-cc-to-gir-scanner.mingw.patch")
md5sums=('10dcb979a57c0cbaa72d2d04c6adc32c'
         '3c7272e976739188a3471b76c8a36fb5'
         '727c1b414987f6ee2ba841d9db57a967')

prepare() {
  cd "$srcdir/poppler-$pkgver"
  patch -p1 -i "$srcdir/poppler-0.26-mingw-wstring.patch"
  patch -p1 -i "$srcdir/give-cc-to-gir-scanner.mingw.patch"
  #sed -i -e '/AC_PATH_XTRA/d' configure.ac
  #sed -i "s:AM_CONFIG_HEADER:AC_CONFIG_HEADERS:" configure.ac
  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-xpdf-headers \
    --enable-zlib \
    --enable-libcurl \
    --disable-gtk-test \
    --enable-utils \
    --disable-gtk-doc-html \
    --with-font-configuration=win32
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="$pkgdir" install
}
